import re
from django_redis import get_redis_connection
from rest_framework import fields, serializers
from django.conf import settings
# from rest_framework_jwt.views import obtain_jwt_token
from rest_framework_jwt.settings import api_settings

from .models import Area


class AreaSerializer(serializers.ModelSerializer):
    # subs = serializers.ManyRelatedField(many=True)
    # subs = serializers.StringRelatedField(many=True)
    # subs = serializers.SlugRelatedField(queryset=Area.objects.all(), slug_field=)

    def to_representation(self, instance):
        ret = super().to_representation(instance)
        # ret['subs'] = {i.id : i.name for i in instance.subs.all()}
        ret['subs'] = [{'id': i.id, 'name': i.name} for i in instance.subs.all()]
        return ret

    class Meta:
        model = Area
        fields = ('id', 'name', 'subs', 'superior')
